package controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import vista.JFFraseIntermedio;

import modelo.Frases;
import modelo.FrasesDao;


public class ControladorJFFraseIntermedio implements ActionListener{
	
	private JFFraseIntermedio ventanaIntermedio;
	private Frases fraseIntermedio;
	
	public ControladorJFFraseIntermedio() {
		super();
		ventanaIntermedio=new JFFraseIntermedio();
		fraseIntermedio=new Frases();
		ventanaIntermedio.addListener(this);
		ventanaIntermedio.setLocationRelativeTo(null);
		ventanaIntermedio.setVisible(true);	
	}

@Override
public void actionPerformed(ActionEvent e) {
	FrasesDao frasesDao = new FrasesDao();
	if (e.getActionCommand().equals("Aceptar"))
	{
		if(ventanaIntermedio.getTxt1().getText().equals("")||ventanaIntermedio.getTxt2().getText().equals("")||ventanaIntermedio.getTxt3().getText().equals(""))
			ventanaIntermedio.mostrarMensaje("Debe Introducir mas de 2 palabras");
		else{
			this.fraseIntermedio.setNivel(Integer.parseInt(ventanaIntermedio.getLblcodigo().getText()));
			this.fraseIntermedio.setNombre(ventanaIntermedio.getTxt1().getText()+" "+ ventanaIntermedio.getTxt2().getText()+" "+ ventanaIntermedio.getTxt3().getText()+" "+ ventanaIntermedio.getTxt4().getText()+" "+ ventanaIntermedio.getTxt5().getText());
			frasesDao.insertarFraseIntermedia(fraseIntermedio);
			this.ventanaIntermedio.Limpiar();
		}
		
		
	}	
}
}

